package com.yuanfengerp.Announcement.controller;

import com.alibaba.fastjson.JSON;
import com.yuanfengerp.Announcement.model.Announcement;
import com.yuanfengerp.Announcement.service.IAnnouncementService;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;

@RestController
@CrossOrigin
public class AnnouncementController {
    @Autowired
    private IAnnouncementService ias;
    @PostMapping("/getAnnouncementList")
    public ArrayList<Announcement> getAnnouncementList(int pageSize, int offset){
        return ias.getAnnouncementList(pageSize,offset);
    }
    @PostMapping("/getAnnouncement")
    public String getAnnouncement(String caption, Date creation_time, Integer status , int notification_id){
        return JSON.toJSONString(ias.getAnnouncement(caption,creation_time,status,notification_id));
    }
    @PostMapping("/addAnnouncement")
    public Result<Announcement> addAnnouncement(@RequestBody Announcement announcement){
        return ias.addAnnouncement(announcement);
    }
    @PostMapping("/publishAnnouncement")
    public Result<Announcement> publishAnnouncement(@RequestBody Announcement announcement){
        return ias.publishAnnouncement(announcement);
    }
    @PostMapping("/selectAnnouncementById")
    public Result<Announcement> selectAnnouncementById(int notification_id){
        return ias.selectAnnouncementById(notification_id);
    }
    @PostMapping("/updateAnnouncement")
    public Result<Announcement> updateAnnouncement(@RequestBody Announcement announcement){
        return ias.updateAnnouncement(announcement);
    }
}
